<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;
use think\Db;
use think\Hook;
use think\Config;
use EasyWeChat\Foundation\Application;
use addons\wechat\library\Config as ConfigService;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        Db::name('config')->where(['name' => 'view'])->setInc('value');
        $siteView = Db::name('config')->where(['name' => 'view'])->value('value');
        session('area_id', $this->area[0]['id']);
        $category = Db::name('category')->where(['type' => 'default', 'status' => 'normal'])->field('id,name,image')->select();
        $banner = Db::name('ad')->where(['type' => 1])->order('sort asc')->limit(6)->select();
        $adlist = Db::name('ad')->where(['type' => 2])->order('sort asc')->limit(20)->select();
        $article = Db::name('article')->limit(3)->select();
        $this->assign('banner', $banner);
        $this->assign('category', $category);
        $this->assign('siteView', $siteView);
        $this->assign('adlist', $adlist);
        $this->assign('article', $article);
        $this->assign('title', '首页');
        // 分享
        $app = new Application(ConfigService::load());
        $js = $app->js;
        $this->assign('js', $js);
        return $this->view->fetch();
    }

    public function setarea()
    {
        $area_id = $this->request->param('area_id');
        if($this->request->isAjax())
        {
            session('area_id', $area_id);
        }
    }

}
